// Pages/theme/theme.js
import {Theme} from "./theme_model.js";
var theme = new Theme;
Page({

  /**
   * 页面的初始数据
   */
  data: {
  
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
     var id = options.id;
     var name = options.name;
     this.data.id = id;
     this.data.name = name;
     this._onloadData();
  },
   _onloadData:function(){
      theme.getProductsData(this.data.id, (res) => {
         this.setData({
            productsArray:res.products,
            productImg:res.head_img.url
         }) 
      })
   },
   //跳转到商品页面
   onProductsItemTap: function (event) {
      var id = theme.getDataSet(event, 'id')
      wx.navigateTo({
         url: '../product/product?id=' + id,
      })
   },
   onReady: function () {
      //设置导航栏的文字
      wx.setNavigationBarTitle({
         title: this.data.name,
      });
      //设置导航栏的加载效果
      wx.showNavigationBarLoading();
      //取消导航栏的加载效果
      setTimeout(function () {
         wx.hideNavigationBarLoading();
      }, 2000);
      //导航栏的动画效果
      wx.setNavigationBarColor({
         frontColor: '#ffffff',
         backgroundColor: '#ff0000',
         animation: {
            duration: 5000,
            timingFunc: 'easeInOut'
         },
         success: function () {
            console.log('setNavigationBarColor');
         }
      })
   },
})